﻿package mortal.game.view.shopMall.view
{
    import Message.Game.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.mvc.core.*;

    public class ShopRebateItemPanel extends ShopCommonPanel
    {
        private var _rechargeBtn:GLoadingButton;
        private var _goldBindText:GTextFiled;
        private var _goldText:GTextFiled;
        private var _bmpYuanbao:GBitmap;
        private var _bmpYuanbaoBind:GBitmap;
        private var _titleBitmap:GImageBitmap;
        private var _specialRebatPanel:SpecialRebatPanel;
        protected var _min:BitmapNumberText;
        protected var _hour:BitmapNumberText;
        protected var _secView:SecTimerView;

        public function ShopRebateItemPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._titleBitmap = UIFactory.gImageBitmap(ImagesConst.ShopMallReBateTitle, 18, 0, this);
            this._specialRebatPanel = UICompomentPool.getUICompoment(SpecialRebatPanel);
            this._specialRebatPanel.x = 520;
            this._specialRebatPanel.y = 100;
            this.addChild(this._specialRebatPanel);
            _goodsList.setSize(550, 480);
            _goodsList.columnWidth = 240;
            _goodsList.rowHeight = 104;
            _goodsList.horizontalGap = 8;
            _goodsList.verticalGap = 5;
            _goodsList.y = 105;
            _goodsList.setStyle("cellRenderer", RebateShopCellRender);
            addChild(_goodsList);
            this._hour = UIFactory.bitmapNumberText(630, 66, "investmentNum.png", 24, 30, -8, this, 9, 1);
            this._hour.text = "23";
            this._min = UIFactory.bitmapNumberText(701, 66, "investmentNum.png", 24, 30, -8, this, 9, 1);
            this._min.text = "59";
            this._secView = UIFactory.secTimeView(Language.getString(30055), 610, 341, 0, 0, null);
            this._secView.configEventListener(EventName.SecViewTimeChange, this.onTimeChangeHd);
            this.setTimeCountDown();
            var _loc_1:* = GlobalStyle.textFormatHuang;
            _loc_1.size = 12;
            _loc_1.bold = true;
            this.pushUIToDisposeVec(UIFactory.bg(450, 437, 178, 18, this, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.bg(450, 463, 178, 18, this, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35569), 455, 437, 100, 30, this, _loc_1.left(), true));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35570), 453, 463, 100, 30, this, _loc_1.left(), true));
            _loc_1.align = AlignMode.RIGHT;
            this._goldText = UIFactory.gTextField("", 503, 439, 100, 30, this, _loc_1, true);
            this._goldBindText = UIFactory.gTextField("", 503, 466, 100, 30, this, _loc_1, true);
            this._bmpYuanbao = UIFactory.gBitmap(ImagesConst.Yuanbao, 605, 437, this);
            this._bmpYuanbaoBind = UIFactory.gBitmap(ImagesConst.Yuanbao_bind, 605, 463, this);
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.ShopRechargeBtn, 630, 444, 124, 37, this);
            this._rechargeBtn.configEventListener(MouseEvent.CLICK, this.rechargeMoney);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._goldBindText.dispose(param1);
            this._goldText.dispose(param1);
            this._bmpYuanbao.dispose(param1);
            this._bmpYuanbaoBind.dispose(param1);
            this._rechargeBtn.dispose(param1);
            this._goldBindText = null;
            this._goldText = null;
            this._bmpYuanbao = null;
            this._bmpYuanbaoBind = null;
            this._rechargeBtn = null;
            this._titleBitmap.dispose(param1);
            this._titleBitmap = null;
            this._specialRebatPanel.dispose(param1);
            this._specialRebatPanel = null;
            this._hour.dispose(param1);
            this._hour = null;
            this._min.dispose(param1);
            this._min = null;
            this._secView.dispose();
            this._secView = null;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateShopClose));
            super.disposeImpl(param1);
            return;
        }// end function

        private function rechargeMoney(event:MouseEvent) : void
        {
            GameUtil.gotoRecharge(ModuleTypeConst.ShopMall);
            return;
        }// end function

        override public function updateMoney(param1:Object = null) : void
        {
            var _loc_2:* = Cache.instance.role.money;
            var _loc_3:* = MoneyUtil.getCoinHtml(_loc_2.gold);
            this._goldText.htmlText = _loc_3;
            _loc_3 = MoneyUtil.getCoinHtml(_loc_2.goldBind);
            this._goldBindText.htmlText = _loc_3;
            return;
        }// end function

        override protected function updatePageSelecter() : void
        {
            var _loc_1:* = ShopConfig.instance.rebateShopMap[Cache.instance.shop.curShopId];
            if (_loc_1)
            {
                _pageSelecter.maxPage = Math.ceil((_loc_1.length - 1) / ShopUtil.getShopMallTabObjByShopCode(0).showItemNum);
            }
            _pageSelecter.currentPage = 1;
            return;
        }// end function

        protected function setTimeCountDown() : void
        {
            var _loc_1:* = this.getLeftTime();
            this._secView.stop();
            if (_loc_1 < 0)
            {
                return;
            }
            this._secView.setLeftTime(_loc_1);
            return;
        }// end function

        protected function getLeftTime() : Number
        {
            return RebateUtil.getTodayLeftTime();
        }// end function

        protected function onTimeChangeHd(event:DataEvent) : void
        {
            if (this._secView == null)
            {
                return;
            }
            if (this._secView.secTimerViewData == null)
            {
                this._secView.stop();
                return;
            }
            var _loc_2:* = this._secView.secTimerViewData.hh();
            var _loc_3:* = this._secView.secTimerViewData.mm();
            this._hour.text = "" + _loc_2;
            this._min.text = "" + _loc_3;
            return;
        }// end function

        override public function getItemsByTab(param1:int, param2:int = 0, param3:int = -1) : void
        {
            if (Cache.instance.shop.curShopId != -1)
            {
                this.onUpdateRebate();
                _goodsList.selectedIndex = param3;
            }
            return;
        }// end function

        override public function getItemsByTabAndPage(param1:int, param2:int, param3:int = 0, param4:int = -1) : void
        {
            if (Cache.instance.shop.curShopId != -1)
            {
                this.onUpdateRebate();
                _goodsList.selectedIndex = param4;
            }
            return;
        }// end function

        public function onUpdateRebate() : void
        {
            _goodsList.dataProvider = this.getPanicBuyDataProvider();
            this.updatePageSelecter();
            return;
        }// end function

        private function getPanicBuyDataProvider() : DataProvider
        {
            var _loc_2:Array = null;
            var _loc_3:Object = null;
            var _loc_4:RebateItemData = null;
            var _loc_5:int = 0;
            var _loc_1:* = new DataProvider();
            if (Cache.instance.shop.isHasGetServerPanicInfo)
            {
                _loc_2 = ShopConfig.instance.rebateShopMap[Cache.instance.shop.curShopId];
                if (_loc_2)
                {
                    _loc_5 = 1;
                    while (_loc_5 < _loc_2.length)
                    {
                        
                        if (Cache.instance.shop.isGetRebatInfoByItemCode(_loc_2[_loc_5].itemCode))
                        {
                            _loc_3 = {data:_loc_2[_loc_5]};
                            _loc_1.addItem(_loc_3);
                        }
                        _loc_5++;
                    }
                    _loc_3 = {data:_loc_2[0]};
                    this._specialRebatPanel.updateShopItem(_loc_3);
                }
            }
            return _loc_1;
        }// end function

        public function shopShowArrow() : void
        {
            this._specialRebatPanel.shopShowArrow();
            return;
        }// end function

    }
}
